import requests
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from LLMClient.QwenClient import Qwen_model_client as model_client


#定义代理可以使用的简单功能工具。
#对于本例，我们使用假天气工具进行演示。
async def get_weather(city: str) -> str:
    """Get the weather for a given city."""
    return f" {city} 天气为73度，阳光明媚."

#星座运势预测接口
def get_constellation_info(type:str, time:str):
    """获取星座运势
    参数：
    type: 十二星座对应英文小写，aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, sagittarius, capricorn, aquarius, pisces
    time:今日明日一周等运势,today, nextday, week, month
    """
    url = "https://api.vvhan.com/api/horoscope"
    params = {
        "type": type,
        "time": time,
    }
    response = requests.get(url, params=params)
    return response.json()

#定义启用模型、工具、系统消息和反射的Assistant Agent。
#系统消息通过自然语言指示代理。
agent = AssistantAgent(
    name="weather_agent",
    model_client=model_client,
    tools=[get_weather,get_constellation_info],
    system_message="你是一个乐于助人的AI助手。",
    reflect_on_tool_use=True,
    model_client_stream=True,  # 流式加载.
)


# 运行代理并将消息流式传输到控制台.
async def main() -> None:
    while True:
        input_ = input("user：")
        if input_ == "exit":
            await model_client.close()
            break
        await Console(agent.run_stream(task=input_))
    



